package com.xyz.threadPoolAndOther;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

@Data
@AllArgsConstructor
@NoArgsConstructor
class User{
    private Integer id;
    private String userName;
    private int age;
}

/**
 * @author 肖咉卓
 *
 * 题目:请按照给出数据，找出同时满足以下条件的用户,也即以下条件全部满足
 * 們数ID且年龄大F24且用户名转为大写且用户名字母倒排序
 * 只输出一个用户名字
 */
public class StreamDemo {
    public static void main(String[] args) {
        User u1 = new User(11,"a",23);
        User u2 = new User(12,"b",24);
        User u3 = new User(13,"c",22);
        User u4 = new User(14,"d",28);
        User u5 = new User(16,"e",26);
        List<User> list = Arrays.asList(u1,u2,u3,u4,u5);
        list.stream().filter(t -> {
            return t.getId() % 2== 0;
        }).filter(t -> {
            return t.getAge()>24;
        }).map(t ->{
            return t.getUserName().toUpperCase();
        }).sorted((o1,o2) -> {
            return o2.compareTo(o1);
        }).limit(1).forEach(System.out::println);








        /*//4大函数式接口
        Function<String,Integer> function = s ->{return s.length(); };
        System.out.println(function.apply("abc"));

        Predicate<String> predicate= s ->{return true; };
        System.out.println(predicate.test("xyz"));

        Consumer<String> consumer = s ->{System.out.println("你输入的是："+s);};
        consumer.accept("Love");

        Supplier<String> supplier= () ->{return "这是输出的";};
        System.out.println(supplier.get());*/

       /*  //普通方法
        List<User> users= new ArrayList<>();
        for (User user : list) {
            if(user.getId()%2==0&&user.getAge()>24){
                System.out.println(user);
                user.setUserName(user.getUserName().toUpperCase());
                users.add(user);
            }
        }
        Collections.reverse(users);
        System.out.println(users.get(0).getUserName());*/
    }
}
